# frozen_string_literal: true

require 'singleton'
require 'net-telnet'

class IRC
  include Singleton

  @client = nil
  @joined = false

  def self.connect
    @client = Net::Telnet.new(
      'Host' => 'bridge',
      'Port' => 6667,
      'Prompt' => '',
      'Telnetmode' => false
    )
    @client.cmd('NICK test') { |c| puts c }
    @client.cmd('USER test 0 * test') { |c| puts c }
  end

  def self.join(channel)
    if @joined
      quit
      connect
      @joined = false
    end
    @client.cmd("JOIN #{channel}") { |c| puts c }
    @joined = true
  end

  def self.quit
    @client.cmd('QUIT') { |c| puts c }
  end

  def self.send_message(channel, msg)
    @client.cmd("PRIVMSG #{channel} :#{msg}") { |c| puts c }
  end
end
